@extends('admin.mainlayout')
@section('title')
    <div class="title"><span>添加品牌></span></div>
    @endsection
    @section('content')
        <!-- 基本信息 -->
    <div class="three">
        <div class="body">
            <!--基本信息-->
            <form enctype="multipart/form-data" id="form">
            <div class="left">
                <div class="one">
                    <p>用户名</p>
                    <input type="text" name="username" value=""/>
                </div>
                <div class="one">
                    <p>密码</p>
                    <input type="password" name="password" value=""/>
                </div>
                <div class="one">
                    <p>确认密码</p>
                    <input type="password" name="cpassword" value=""/>
                </div>
                <div class="one">
                    <p>品牌名称</p>
                    <input type="text" name="brand_name" value=""/>
                </div>
                <div class="one">
                    <p>负责人</p>
                    <input type="text"  name="name" value=""/>
                </div>
                <div class="one">
                    <p>手机</p>
                    <input type="text"  name="mobile" value=""/>
                </div>
                <div class="one">
                    <p>地址</p>
                    <input type="text"  name="address" value=""/>
                </div>
                <div class="two" style="position: absolute;top: 100px;right: 200px;">
                    <p>营业执照</p>
                    <img src="" id="prev_img" alt=""/>
                    <span>点击上传图片 <input type="file" name="pics" id="doc-ipt-file-1"></span>
                    <input id='hidimg' type="hidden" name="img" value="">
                </div>
                <div class="save" id='fabu'>保存</div>
            </div>
            </form>
        </div>
    </div>
    <script>
        var message = "{{Session::get('message')}}";
        $(window).ready(function () {
            if (message) {
                layer.msg(message, {
                    time: 3000 //2秒关闭（如果不配置，默认是3秒）
                });
            }
        });

        window.onload = function() {
            var file = document.getElementById('doc-ipt-file-1');
            var img = document.getElementById('prev_img');
            var hidimg = document.getElementById('hidimg');
            file.onchange = function () {
                var oFReader = new FileReader();
                oFReader.readAsDataURL(this.files[0]);
                oFReader.onload = function (oFREvent) {
                    img.src = oFREvent.target.result;
                    hidimg.value = oFREvent.target.result;
                };
            }
        }

        $('#fabu').click(function(){

            layer.confirm('确定要发布?',{btn:['确定','取消']},function(){
                layer.closeAll();
                layer.load(2, {shade: false});
                $.ajax({
                    type:'post',
                    url:"{{urlAdmin('Brand','postAdd')}}",
                    data:$('form').serializeArray(),
                    dataType:'json',
                    success:function(res){
                        //关闭所有层
                        layer.closeAll();
                        if(res.status==1){
                            layer.msg(res.msg, {icon: 6});
                            //setTimeout("location.reload()",2000);
                            setTimeout("location.href='{{urlAdmin("Brand","getIndex")}}'",2000);
                        }else{
                            layer.msg(res.msg, {icon: 5});
                        }
                    }
                });

            },function(){});

        });
    </script>
@endsection
